package org.test.client.ui.skinui.checkbox;

import java.awt.Component;
import java.awt.Graphics;
import java.io.Serializable;

import javax.swing.ButtonModel;
import javax.swing.Icon;
import javax.swing.JCheckBox;

public class CheckBoxIcon implements Icon, Serializable {

	public void paintIcon(Component c, Graphics g, int x, int y) {
		JCheckBox cb = (JCheckBox) c;
		ButtonModel model = cb.getModel();

		// ѡ��ʱ
		if (model.isSelected()) {
			// ���ڽ���״̬
			if (!model.isEnabled())
				g.drawImage(PicFactory.getCheckBoxIcon(PicFactory.CB_DISABLE), x, y, null);
			else {
				// ���ڱ���ס״̬
				if (model.isPressed())
					g.drawImage(PicFactory.getCheckBoxIcon(PicFactory.CB_PRESSED), x, y, null);
				else
					g.drawImage(PicFactory.getCheckBoxIcon(PicFactory.CB_NORMAL), x, y,null);
			}
		}
		// δѡ��ʱ
		else {
			// ���ڽ���״̬
			if (!model.isEnabled())
				g.drawImage(PicFactory.getCheckBoxIcon(PicFactory.CB_UN_DISABLE),x, y, null);
			else {
				// ���ڱ���ס״̬
				if (model.isPressed())
					g.drawImage(PicFactory.getCheckBoxIcon(PicFactory.CB_UN_PRESSED), x, y, null);
				else
					g.drawImage(PicFactory.getCheckBoxIcon(PicFactory.CB_UN_NORMAL), x, y, null);
			}
		}
	}

	public int getIconWidth() {
		return 24;
	}

	public int getIconHeight() {
		return 24;
	}

} // end class CheckBoxIcon